package com.bruan.d1_collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

public class CollectionTest2API {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        //添加数据 add()
        collection.add("java1");
        collection.add("java1");
        collection.add("java1");
        collection.add("java1");
        collection.add("java1");
        System.out.println(collection);
        //清空数据 clear()
        collection.clear();
        System.out.println(collection);
        //判断是否为空 isEmpty()
        collection.add("java1");
        collection.add("java1");
        collection.add("java1");
        collection.add("java1");
        System.out.println(collection.isEmpty());
        //获取集合大小 size()
        System.out.println(
                collection.size()
        );
        //删除某个元素 remove()
        collection.remove("java1");
        System.out.println(collection);
        //集合-》数组
        Object[] arr=collection.toArray();
        System.out.println(Arrays.toString(arr));

        System.out.println("--------------------------");
        //把一个集合的全部数据放入另一个集合
        Collection<String> c1 = new ArrayList<>();
        c1.add("java1");
        c1.add("java1");
        c1.add("java1");
        Collection<String> c2 = new ArrayList<>();
        c2.add("java2");
        c2.add("java2");
        c2.add("java2");
        c1.addAll(c2);//c2数据导入c1
        System.out.println(c1);
        System.out.println(c2);

    }
}
